using System.Data.Entity;

using SC.Infrastructure.Persistence.Interfaces;

using Sc.Domain.Interfaces;

namespace SC.Infrastructure.Persistence
{
	public class UnitOfWork : IUnitOfWork
	{
		private readonly DbContext _innerContext;

		public UnitOfWork()
		{
			this._innerContext = new Context();
			// _context.Database.Initialize(true);
		}

		internal DbContext InnerContext
		{
			get
			{
				return this._innerContext;
			}
		}

		public IRepository<T> GetRepository<T>() where T : class, IEntity
		{
			return new Repository<T>(this, this._innerContext.Set<T>());
		}

		public int SaveChanges()
		{
			return this._innerContext.SaveChanges();
		}

		public void Dispose()
		{
			this._innerContext.Dispose();
		}
	}
}